package com.example.agboxdemo.entity.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.agboxdemo.entity.po.UserCar;
import com.example.agboxdemo.entity.dao.UserCarMapper;
import com.example.agboxdemo.entity.service.IUserCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hnn
 * @since 2025-07-10
 */
@Service
public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> implements IUserCarService {

    @Override
    public boolean updateByCredential(UserCar userCar) {
        return saveOrUpdate(userCar, Wrappers.lambdaUpdate(UserCar.class)
                .eq(UserCar::getPlateNo, userCar.getPlateNo())
                .eq(UserCar::getPlateTypeCode, userCar.getPlateTypeCode())
                .set(UserCar::getCredentialType, userCar.getCredentialType())
                .set(UserCar::getCredentialNo, userCar.getCredentialNo())
                .set(UserCar::getCarTypeCode, userCar.getCarTypeCode())
                .set(UserCar::getEnabled, userCar.getEnabled())
        );
    }

    @Override
    public UserCar getByPlate(String plateNo, Integer plateTypeCode) {
        return getOne(Wrappers.lambdaQuery(UserCar.class)
                .eq(UserCar::getPlateNo, plateNo)
                .eq(UserCar::getPlateTypeCode, plateTypeCode));
    }
}
